<?php
/**
 * User: taodf
 * Date: 17-4-29
 * Time: 下午1:18
 */

namespace Zeus\View\Engines;

use Zeus\View\Exceptions\NotSupportedEngineException;

/**
 * 视图渲染引擎的构造工厂
 *
 * Class EngineFactory
 * @package Zeus\View\Engines
 */
abstract class EngineFactory
{
    /**
     * 支持的引擎类型
     * @var array $supportedEngines
     */
    const SupportedEngines=[
        "plates"=>PlateEngine::class,
        "twig"=>TwigEngine::class,
        "mustache"=>MustacheEngine::class,
        "haml"=>HamlEngine::class,
        "lex"=>LexEngine::class,
        "tal"=>TalEngine::class
    ];

    /**
     * 创建不同的视图引擎
     *
     * @param string $name
     * @param string $folder
     * @return mixed
     * @throws NotSupportedEngineException
     */
    public static function createEngine($name="plates", $folder)
    {
        $name=strtolower($name);
        if(false===array_key_exists($name, self::SupportedEngines)){
            throw new NotSupportedEngineException();
        }
        $class=self::SupportedEngines[$name];
        return new $class($folder);
    }
}